public class test4 {
    class Solution {
        public boolean wordPattern(String pattern, String s) {
            //双映射
            HashMap<Character,String> c2s = new HashMap<>();
            HashMap<String,Character> s2c = new HashMap<>();
            String[] strs = s.split(" ");
            if(pattern.length()!=strs.length){
                return false;
            }
            int len = strs.length;
            for(int i = 0;i<len;i++){
                if(c2s.containsKey(pattern.charAt(i)) && !strs[i].equals(c2s.get(pattern.charAt(i))) || s2c.containsKey(strs[i]) && s2c.get(strs[i])!=pattern.charAt(i)){
                    return false;
                }
                c2s.put(pattern.charAt(i),strs[i]);
                s2c.put(strs[i],pattern.charAt(i));
            }
            return true;
        }
    }
}
